package com.itheima.reggie.mapper;

import com.itheima.reggie.controller.CategoryController;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.entity.Dish;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface CategoryMapper {

    @Insert("insert into category values(null,#{type},#{name},#{sort},"+
            "#{createTime},#{updateTime},#{createUser},#{updateUser})")
    Integer save(Category category);

    @Select("select * from category where name=#{name}")
    Category findByName(String name);

    @Select("select * from category order by sort")
    List<Category> findByPage();

    @Delete("delete  from category where id=#{id}")
    Integer deleteByid(Long id);

    Integer update(Category category);


    @Select("select * from category where name=#{name} and id !=#{id}")
    Category findByName2(Category category);

    //根据类型查询类别列表数据
    List<Category> findAllByType(@Param("type") Integer type);

    //分页查询 ：第二条sql 根据类别id查询类别对象
    @Select("select * from category where id=#{id}")
    Category findById(Long id);

}
